'use strict';
// SKU表
module.exports = app => {
  const { STRING, TINYINT, BIGINT, TEXT } = app.Sequelize;

  const MallSku = app.model.define('mall_sku', {
    spu_id: {
      type: BIGINT(20),
      allowNull: false,
      comment: 'SPU Id',
    },
    title: {
      type: STRING(256),
      allowNull: false,
      comment: '商品标题',
    },
    images: {
      type: STRING(256),
      defaultValue: '',
      comment: '商品图片 (多个图片用,号分割)',
    },
    stock: {
      type: BIGINT,
      defaultValue: 0,
      comment: '库存',
    },
    price: {
      type: BIGINT(16),
      allowNull: false,
      defaultValue: 0,
      comment: '销售价格 (单位为分)',
    },
    indexes: {
      type: STRING(32),
      defaultValue: '',
      comment: '特有规格参数在SPU规格模板中对应的下标组合(如1_0_0)',
    },
    own_spec: {
      type: TEXT,
      defaultValue: '',
      comment: 'SKU的特有规格参数键值对 (json格式，反序列化时请使用linkedHashMap，保证有序)',
    },
    // own_spec: {
    //   type: STRING(1024),
    //   defaultValue: '',
    //   comment: 'SKU的特有规格参数键值对 (json格式，反序列化时请使用linkedHashMap，保证有序)',
    // },
    enable: {
      type: TINYINT(1),
      allowNull: false,
      defaultValue: 1,
      comment: '是否有效 (0-无效，1-有效)',
    },


  });

  // MallSpecParam.associate = () => {
  //   // 存在多对一关系，所以使用belongsTo()
  //   MallSpecParam.associate = () => {
  //     app.model.MallSpecParam.belongsTo(app.model.MallCategory, { foreignKey: 'category_id' });
  //   };
  //   MallSpecParam.associate = () => {
  //     app.model.MallSpecParam.belongsTo(app.model.MallSpecGroup, { foreignKey: 'group_id' });
  //   };
  // };
  return MallSku;
};
